#!/usr/bin/python
#coding=utf-8

class Router(object):
    
    def __init__(self):
        self.path_mapper = {}

    def route(self, req, resp):
        path = req.path_info 
        if path.endswith('/'):
            req.path_info = path[:-1]
        application = self.path_mapper.get(req.path_info)  
        if application is None:
            return resp.redirect(req, '/demo/notfound')
        return application(req, resp)  

    def __call__(self, path):  
        def wrapper(application):  
            self.path_mapper[path] = application  
        return wrapper  

    
